﻿//作者：HXL，如有疑问，可以QQ：991044981


//分页控件单击事件
function pageClick(callBack) {
    $("#1_fenyeId li").click(function () {
        var id = $(this).attr("id");
        if ($("#"+id).html() == pageIndex) {
            return;
        }
        if(id == "textId" || id=="countPageId"){
        	return;
        }
       
        if (id == "prev") {
        	if(pageIndex>1) {
        		 pageIndex--;
        	}else{
        		return;
        	}
           
        }
        else if (id == "next") {
        	if(pageIndex<pageCount){
        		pageIndex++;
        	}else{
        		return;
        	}
        }
        else {
            pageIndex =$("#"+id).html();
        }
        if (pageIndex < 1 || pageIndex > pageCount) {
            return;
        }
        pageIndex = parseInt(pageIndex);
        callBack();
    });
}

//刷新分页控件
function pageRefresh(callBack) {
   // $("#pagedes").html("共<a>" + recordCount + "</a>条数据");
    if (recordCount > 0) {
    	$("#1_fenyeId").empty();
        if (recordCount % pageSize == 0) {
            pageCount = recordCount / pageSize;
        }
        else {
            pageCount = (recordCount - recordCount % pageSize) / pageSize + 1;
        }
        pageIndex = parseInt(pageIndex);
        if (pageIndex < 1) {
            pageIndex = 1;
        }
        else if (pageIndex > pageCount) {
            pageIndex = pageCount;
        }
        var pagelist = "";
        if (pageIndex == 1) {
           // pagelist = "<span  class='prev-disabled'>上一页<b></b></span> " + "<a id='1'>1</a> ";
        	pagelist = "<li id='prev' >上一页<b></b></li> " + "<li id='1'>1</li> ";
        }
        else {
            pagelist = "<li id='prev'>上一页<b></b></li> " + "<li id='1'>1</li> ";
        }
        if (pageIndex - 2 > 2) {
            pagelist += "<li id='textId'>...</li> ";
        }
        if (1 < pageIndex - 2 && pageIndex - 2 < pageCount) {
            pagelist += "<li id='" + (pageIndex - 2) + "'>" + (pageIndex - 2) + "</li> ";
        }
        if (1 < pageIndex - 1 && pageIndex - 1 < pageCount) {
            pagelist += "<li id='" + (pageIndex - 1) + "'>" + (pageIndex - 1) + "</li>";
        }
        if (1 < pageIndex && pageIndex < pageCount) {
            pagelist += "<li id='" + pageIndex + "'>" + pageIndex + "</li> ";
        }
        for (var i = pageIndex + 1; i < pageCount && i <= pageIndex + 2; i++) {
            pagelist += "<li id='" + i + "'>" + i + "</li> ";
        }
        if (pageIndex + 3 < pageCount) {
            pagelist += "<li id='textId' class='text'>...</li> ";
        }
        if (pageIndex < pageCount) {
            pagelist += "<li id='" + pageCount + "'>" + pageCount + "</li> " + "<li id='next'>下一页<b></b></li>";
        }
        else if (pageIndex > 1) {
            pagelist += "<li id='" + pageCount + "'>" + pageCount + "</li> " + "<li id='next'>下一页<b></b></li>";
        }
        else {
            pagelist += "<li id='next'>下一页<b></b></li>";
        }
        pagelist+="<li id=\"countPageId\"><span class=\"pageinfo\">共 <strong>"+pageCount+"</strong>页<strong>"+recordCount+"</strong>条</span></li>";
        $("#1_fenyeId").append(pagelist);
  	  

        $("#" + pageIndex).addClass("thisclass");
        pageClick(callBack);
    }
    else {
        $("#1_fenyeId").empty();
    }
}



